<?php

/**
 * Louder Cache
 *
 * LICENSE
 *
 * This source file is subject to the New BSD License that is bundled
 * with this package in the file docs/LICENSE.txt.
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to info@loudertechnology.com so we can send you a copy immediately.
 *
 * @category Louder
 * @package MemoryRegistry
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */

/**
 * Almacena datos en memoria compartida
 *
 * @category Louder
 * @package MemoryRegistry
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */
class MemoryRegistry {

	/**
	 * Handler de Memcached
	 *
	 * @var Memcached
	 */
	private static $_handler;

	/**
	 * Inicializa el Memcached
	 *
	 */
	static private function _initialize(){
		if(self::$_handler==null){
			self::$_handler = new Memcache();
			self::$_handler->pconnect('127.0.0.1', 11211);
		}
	}

	/**
	 * Establece un valor de memoria
	 *
	 * @param string $index
	 * @param mixed $value
	 */
	static public function set($index, $value){
		self::_initialize();
		self::$_handler->set($index, $value);
	}

	/**
	 * Devuelve un valor de memoria
	 *
	 * @param string $index
	 * @return mixed
	 */
	static public function get($index){
		self::_initialize();
		return self::$_handler->get($index);
	}

}